import 'package:flutter/material.dart';

class ScrollHomePage extends StatefulWidget {
  @override
  _ScrollHomePageState createState() => _ScrollHomePageState();
}

class _ScrollHomePageState extends State<ScrollHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("scroll配置"),
      ),
      // 线性布局
      body: CustomScrollView(
        physics: BouncingScrollPhysics(),
        slivers: [
          SliverAppBar(title: Text("讲解组合动画")),
          SliverPadding(padding: EdgeInsets.all(5)),
          // 九宫格
          SliverGrid(
            delegate: new SliverChildBuilderDelegate(
              (BuildContext context, num index) {
                return Container(
                  color: Colors.blue,
                  child: Text('grid $index'),
                );
              },
              childCount: 10,
            ),
            gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2, // 九宫格列数
                childAspectRatio: 4, //子widget宽高必
                mainAxisSpacing: 10, //主方向 两个 widget之间的间距
                crossAxisSpacing: 10), // 此方向的间距
          ),
          SliverPadding(padding: EdgeInsets.all(5)),
          SliverFixedExtentList(
            delegate: new SliverChildBuilderDelegate(
              (BuildContext context, num index) {
                return Container(
                  color: Colors.red,
                  child: Text("list $index"),
                  margin: EdgeInsets.only(bottom: 20),
                );
              },
              childCount: 20,
            ),
            // 每一个item的高度
            itemExtent: 50,
          ),
        ],
      ),
    );
  }
}
